home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / Buch / Rund2b.cpp < prev    next >
C/C++ Source or Header  |  1998-12-30  |  2KB  |  74 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "Rund2b.h"
  6. //---------------------------------------------------------------------------
  7. #pragma resource "*.dfm"
  8.  
  9. const int FMax = 16;
  10. TColor Farbe[FMax] =
  11.   {clBlack, clMaroon, clGreen, clNavy, clTeal, clPurple,
  12.    clOlive, clGray, clSilver, clRed, clLime, clBlue,
  13.    clAqua, clFuchsia, clYellow, clWhite};
  14.  
  15. TKreis *Kreis;
  16. TForm1 *Form1;
  17. //---------------------------------------------------------------------------
  18. TKreis::TKreis(int xx, int yy, int dd)
  19. {
  20.   x = xx; y = yy; Dicke = dd;
  21. }
  22. //---------------------------------------------------------------------------
  23. void TKreis::Erscheinen (void)
  24. {
  25.   Form1->Canvas->Brush->Color = Farbe[random (FMax)];
  26.   Form1->Canvas->Ellipse (x, y, x+Dicke, y+Dicke);
  27. }
  28. //---------------------------------------------------------------------------
  29. void TKreis::Bewegen (void)
  30. {
  31.   TRect Quelle, Ziel;
  32.   for (int i=x-5; i<Form1->ClientWidth-Dicke-x-5; i++)
  33.   {
  34.     Quelle = Rect(i,   y-5, i+Dicke+5, y+Dicke+5);
  35.     Ziel   = Rect(i+1, y-5, i+Dicke+6, y+Dicke+5);
  36.     Form1->Canvas->CopyRect(Ziel, Form1->Canvas, Quelle);
  37.     // Bremse, abhΣngig vom Prozessortakt!
  38.     for (int j=0; j<1000000; j++) ;
  39.   }
  40. }
  41. //---------------------------------------------------------------------------
  42. void TKreis::Verschwinden (void)
  43. {
  44.   Form1->Refresh ();
  45. }
  46. //---------------------------------------------------------------------------
  47. __fastcall TForm1::TForm1(TComponent* Owner)
  48.     : TForm(Owner)
  49. {
  50. }
  51. //---------------------------------------------------------------------------
  52. void __fastcall TForm1::Button1Click(TObject *Sender)
  53. {
  54.   Kreis->Erscheinen ();
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TForm1::Button2Click(TObject *Sender)
  58. {
  59.   Kreis->Bewegen ();
  60. }
  61. //---------------------------------------------------------------------------
  62. void __fastcall TForm1::Button3Click(TObject *Sender)
  63. {
  64.   Kreis->Verschwinden ();
  65. }
  66. //---------------------------------------------------------------------------
  67. void __fastcall TForm1::FormCreate(TObject *Sender)
  68. {
  69.   randomize ();
  70.   Color = Farbe[random (16)];
  71.   Kreis = new TKreis (30, 30, 150);
  72. }
  73. //---------------------------------------------------------------------------
  74.